home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / public / rayshade / etc / rsconvert / lex.l next >
Text File  |  1994-08-01  |  4KB  |  165 lines

  1. /* lex.l                                   */
  2. /* Copyright (C) 1989, 1991, Craig E. Kolb                   */
  3. /* All rights reserved.                               */
  4. /*                                       */
  5. /* This software may be freely copied, modified, and redistributed,       */
  6. /* provided that this copyright notice is preserved on all copies.       */
  7. /*                                       */
  8. /* You may not distribute this software, in whole or in part, as part of   */
  9. /* any commercial product without the express consent of the authors.       */
  10. /*                                        */
  11. /* There is no warranty or other guarantee of fitness of this software       */
  12. /* for any purpose.  It is provided solely "as is".               */
  13. /* $Id: lex.l,v 4.0.1.1 91/11/26 21:12:29 cek Exp Locker: cek $ */
  14. %{
  15. #include "config.h"
  16. #include <stdio.h>
  17. #ifdef I_STRING
  18. #include <string.h>
  19. #else
  20. #include <strings.h>
  21. #endif
  22. #include "libcommon/common.h"
  23. #include "y.tab.h"
  24. %}
  25. alpha    [a-zA-Z]
  26. special    [\.\_-]
  27. digit    [0-9]
  28. exp    [Ee][-+]?{digit}+
  29. string    ({alpha}|"/")({alpha}|{digit}|{special}|"/")*
  30. %p 3000
  31. %%
  32. [\t]            {WriteVerbatim(yytext);};
  33. "\n"            {};
  34. " "            {};
  35. ^#            {return handlehash();}
  36. "/*"            {skipcomments();}
  37. adaptive        {return(tADAPTIVE);}
  38. aperture        {return(tAPERTURE);}
  39. background        {return(tBACKGROUND);}
  40. blotch            {return(tBLOTCH);}
  41. box            {return(tBOX);}
  42. bump            {return(tBUMP);}
  43. checker            {return(tCHECKER);}
  44. cone            {return(tCONE);}
  45. contrast        {return(tCONTRAST);}
  46. cutoff            {return(tCUTOFF);}
  47. cylinder        {return(tCYL);}
  48. defend            {return(tENDDEF);}
  49. define            {return(tSTARTDEF);}
  50. directional        {return(tDIRECTIONAL);}
  51. endfile            {return(tENDFILE);}
  52. extended        {return(tEXTENDED);}
  53. eyep            {return(tEYEP);}
  54. fbm            {return(tFBM);}
  55. fbmbump            {return(tFBMBUMP);}
  56. focaldist        {return(tFOCALDIST);}
  57. fog            {return(tFOG);}
  58. fov            {return(tFOV);}
  59. gloss            {return(tGLOSS);}
  60. grid            {return(tGRID);}
  61. heightfield        {return(tHEIGHTFIELD);}
  62. jittered        {return(tJITTERED);}
  63. light            {return(tLIGHT);}
  64. list            {return(tLIST);}
  65. lookp            {return(tLOOKP);}
  66. marble            {return(tMARBLE);}
  67. maxdepth        {return(tMAXDEPTH);}
  68. mist            {return(tMIST);}
  69. object            {return(tOBJECT);}
  70. outfile            {return(tOUTFILE);}
  71. plane            {return(tPLANE);}
  72. point            {return(tPOINT);}
  73. poly            {return(tPOLY);}
  74. resolution        {return(tRESOLUTION);}
  75. rotate            {return(tROTATE);}
  76. samples            {return(tSAMPLES);}
  77. scale            {return(tSCALE);}
  78. screen            {return(tSCREEN);}
  79. sphere            {return(tSPHERE);}
  80. superq            {return(tSUPERQ);}
  81. surface            {return(tSURFACE);}
  82. texture            {return(tTEXTURE);}
  83. transform        {return(tTRANSFORM);}
  84. translate        {return(tTRANSLATE);}
  85. triangle        {return(tTRIANGLE);}
  86. up            {return(tUP);}
  87. wood            {return(tWOOD);}
  88. {string}        {yylval.c = strsave(yytext);
  89.                 return(tSTRING);}
  90. [+-]?{digit}+        {yylval.i = atoi(yytext);
  91.                 return(tINT);}
  92.  
  93. [+-]?{digit}+"."{digit}*({exp})? |
  94. [+-]?{digit}*"."{digit}+({exp})? |
  95. [+-]?{digit}+{exp}        {yylval.d = atof(yytext); return(tFLOAT);}
  96.  
  97. .            {return yytext[0];}
  98.  
  99. %%
  100. yywrap() {return(1);}
  101. /*
  102.  * Skip over comments.
  103.  */
  104. skipcomments()
  105. {
  106.     char c;
  107.  
  108.     WriteVerbatim("/*");
  109.     while (1) {
  110.         while ((c = input()) != '*')
  111.             WriteChar(c);
  112.         WriteChar(c);
  113.         if ((c = input()) == '/') {
  114.             WriteChar(c);
  115.             WriteNewline();
  116.             return;
  117.         }
  118.         unput(c);
  119.     }
  120. }
  121. /*
  122.  * Deal with ccp-produced lines of the form:
  123.  * # n "filename"
  124.  * and
  125.  * # n
  126.  * Where filename is the name of the file being processed, and n is
  127.  * the current line number in that file.
  128.  */
  129. handlehash()
  130. {
  131.     char buf[BUFSIZ];
  132.     int i, linenumber;
  133.     extern int yylineno;
  134.     extern char yyfilename[];
  135.  
  136.     /*
  137.      * Read the entire line into buf.
  138.      */
  139.     for (i = 0; (buf[i] = input()) != '\n'; i++)
  140.             ;
  141.     unput(buf[i]);        /* To make sure consecutive # lines work. */
  142.     buf[i] = (char)NULL;    /* Replace newline with NULL. */
  143.  
  144.     yylval.c = strsave(buf);
  145.  
  146.     /*
  147.      * Set file/line if the line was of the form #n "filename"
  148.      */
  149.     if ((i = sscanf(buf, "%d \"%[^\"]s\"", &linenumber, buf)) != 0) {
  150.         yylineno = linenumber;
  151. #ifdef SYSV
  152.         if (strchr(buf, '"') != (char *)0) {
  153. #else
  154.         if (index(buf, '"') != (char *)0) {
  155. #endif
  156.             /*
  157.              * Filename was "", which means stdin.
  158.              */
  159.             strcpy(yyfilename, "stdin");
  160.         } else
  161.             strcpy(yyfilename, buf);
  162.     }
  163.     return tHASHTHING;
  164. }
  165.